<?php

namespace Admin\Controller;

class ScienceController extends AdminbaseController {

    function _initialize() {
        parent::_initialize();
        $this->currentModel = D("Science");
    }

    //首页
    public function index() {

        $requestMap = $this->convertRequestToMap();

        //分页
        $count = $this->currentModel->getListCount($requestMap);
        $page = $this->page($count, C("DEFAULT_PAGE_SIZE"));

        //获取列表
        $list = $this->currentModel->queryForList($page, $requestMap);

        $this->assign("statusEnum", C("DEFAULT_YN"));
        $this->assign('list', $list);
        $this->assign("page", $page->show('Admin', $this->parameter));
        $this->display();

    }

    /**
     * 添加数据
     */
    public function addPost() {

        $data["title"] = $_REQUEST["title"];
        $data["title_image"] = $_REQUEST["titleImage"];
        $data["content"] = html_entity_decode($_REQUEST["description"]);
        $data["create_time"] = getCurrentDate();
        $data["category_id"] = $_REQUEST["categoryId"];
        $data["second_title"] = $_REQUEST["secondTitle"];
        $data["source"] = $_REQUEST["source"];
        $data["doctor_name"] = $_REQUEST["doctorName"];

        $this->currentModel->add($data);

        $this->success("添加成功", U("science/index"));

    }

    /**
     * 更新数据
     */
    public function editPost() {

        $id = $_REQUEST["id"];

        $data = $this->currentModel->queryById($id);
        $data["title"] = $_REQUEST["title"];
        $data["title_image"] = $_REQUEST["titleImage"];
        $data["content"] = html_entity_decode($_REQUEST["description"]);
        $data["category_id"] = $_REQUEST["categoryId"];
        $data["second_title"] = $_REQUEST["secondTitle"];
        $data["source"] = $_REQUEST["source"];
        $data["doctor_name"] = $_REQUEST["doctorName"];

        $this->currentModel->updateInfo($data);

        $this->success("更新成功", U("science/index"));

    }


}